package com.dfbz.demo01;

import java.util.HashMap;
import java.util.Objects;

/**
 * @author lscl
 * @version 1.0
 * @intro:
 */
public class Demo04_HashMap {
    public static void main(String[] args) {


        HashMap<String,String> map = new HashMap<>();
        map.put("江西","南昌");
        map.put(new String("江西"),"南昌");

        System.out.println(map);                //


/*
        HashMap<City,String> map = new HashMap<>();
        map.put(new City("江西","赣","华东"),"a");
        map.put(new City("江西","赣","华东"),"b");

        System.out.println(map.size());
*/

    }
}

class City {
    private String name;            // 城市名称
    private String shortName;       // 简称
    private String location;            // 所属地区

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        City city = (City) o;
        return Objects.equals(name, city.name) &&
                Objects.equals(shortName, city.shortName) &&
                Objects.equals(location, city.location);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, shortName, location);
    }

    public void intro() {
        System.out.println("名称: " + name + ",简称: " + shortName + ",所属地区: " + location);
    }
    public City() {
    }

    public City(String name, String shortName, String location) {
        this.name = name;
        this.shortName = shortName;
        this.location = location;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getShortName() {
        return shortName;
    }

    public void setShortName(String shortName) {
        this.shortName = shortName;
    }

    public String getLocation() {
        return location;
    }

    public void setLocation(String location) {
        this.location = location;
    }

    @Override
    public String toString() {
        return "City{" +
                "name='" + name + '\'' +
                ", shortName='" + shortName + '\'' +
                ", location='" + location + '\'' +
                '}';
    }
}